<!DOCTYPE html>
<html>
<head lang="en">
	<meta charset='utf-8'/>
	<title>lesson5-请求超时设置</title>
</head>
<body>
<button>发送请求</button>
<script>
	document.querySelector('button').onclick = function (){
		var xhr = new XMLHttpRequest();
		xhr.onreadystatechange = function (){
			if(xhr.readyState == 4){
				if(xhr.status == 200){
					console.log(xhr.responseText);
				}
			}
		};

		xhr.timeout = 5000;
		xhr.ontimeout = function (){
			console.log('连接超时，页面加载失败，请刷新重试');
		};

		xhr.open('get', '04timeout.php', true);
		xhr.send(null);
	};


</script>
</body>
</html>